﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CatchUpTv.Downloader;
using CatchUpTv.Tv;
using System.Windows.Forms;

namespace CatchUpTv.UI
{
    public class EpisodeDownloader
    {
        IDownloader _downloader; 
        Episode _episode; 
        DownloadProgress _progress;

        public EpisodeDownloader(IDownloader downloader, Episode episode, DownloadProgress progress)
        {
            _downloader = downloader;
            _episode = episode;
            _progress = progress;
                        
            string description = string.Format("{0} {1}", episode.Name, episode.FileSize);
            _progress.SetDescription(description);

            downloader.DownloadEpisode(episode, ProgressUpdater);

            _progress.Invoke(new Action<Control>(RemoveProgressBar), _progress);
        }

        private void ProgressUpdater(double percentage, double size)
        {
            _progress.SetProgress(percentage);
        }

        private void RemoveProgressBar(Control c)
        {
            c.Parent.Controls.Remove(c);
        }
    }
}
